//===============================================================================
// Microsoft patterns & practices
// Mobile Client Software Factory - July 2006
//===============================================================================
// Copyright  Microsoft Corporation.  All rights reserved.
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
// LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS FOR A PARTICULAR PURPOSE.
//===============================================================================
// The example companies, organizations, products, domain names,
// e-mail addresses, logos, people, places, and events depicted
// herein are fictitious.  No association with any real company,
// organization, product, domain name, email address, logo, person,
// places, or events is intended or should be inferred.
//===============================================================================

using System;
using System.Reflection;

namespace Microsoft.Practices.Mobile.ObjectBuilder.Utility
{
    /// <summary>
    /// Utility Class to provide missing Enum functionality in .NET CF 2.0
    /// </summary>
    public static class CFEnumUtil
    {
        /// <summary>
        /// Replacement for Enum.GetValues not available in .NET CF 2.0
        /// </summary>
        /// <param name="enumType"></param>
        /// <returns></returns>
        public static Array GetValues(Type enumType)
        {
            if (enumType.BaseType.FullName != "System.Enum")
            {
                throw new ArgumentException(Properties.Resources.TypeMustBeEnum, "enumType");
            }

            System.Collections.ArrayList enumValues = new System.Collections.ArrayList();

            foreach (FieldInfo enumField in enumType.GetFields())
            {
                if (Enum.IsDefined(enumType, enumField.Name))
                {
                    enumValues.Add(enumField.GetValue(enumField));
                }
            }

            return enumValues.ToArray(enumType);
        }
    }
}
